package com.mademoisellegeek.carrentalsimulation.optimisation;

import com.mademoisellegeek.carrentalsimulation.Garage;
import com.mademoisellegeek.carrentalsimulation.OptimisationData;
import com.mademoisellegeek.carrentalsimulation.Optimiser;
import com.mademoisellegeek.carrentalsimulation.enums.SortMethod;
import com.mademoisellegeek.carrentalsimulation.Travel;
import com.mademoisellegeek.carrentalsimulation.Vehicle;

public class OptDepartureNoAdds extends Optimiser {

    public static int[] run(OptimisationData originalData, SortMethod method) {
        OptimisationData data = new OptimisationData(originalData);
        sortRequestList(data, method);
        for (Travel request : data.getRequestList()) {
            Vehicle availableVehicle = getAvailableVehicleOptimised(data, request.getStartTown(), request.getStartDay());
            Garage arrivalGarage = getAnyGarageWithAvailableSpace(data.getGarageDictionary(), request.getEndTown(), request.getEndDay());
            if (availableVehicle != null && arrivalGarage != null) {
                updateOptimisationData(data, availableVehicle, request, arrivalGarage);
            } else {
                data.addFailedRequest(request);
            }
        }
        return new int[]{data.getRequestList().size(),
                    getNumberOfDays(data.getRequestList()),
                    data.getFailedRequests().size(),
                    getNumberOfDays(data.getFailedRequests()),
                    data.getAdditionalTravels().size(),
                    getNumberOfDays(data.getAdditionalTravels())};
    }
}
